package Day2025_02_18;

public class LeetCode209 {
    public int minSubArrayLen(int target, int[] nums) {
        int n = nums.length;
        int left = 0, right = 0;
        int minLen = n + 1;
        int tmp = 0;
        for (right = 0; right < n; right++) {
            tmp += nums[right];
            while (right < n && tmp >= target) {
                minLen = Math.min(minLen, right - left + 1);
                tmp -= nums[left++];
            }
        }
        return minLen == n + 1 ? 0 : minLen;
    }
}
